package com.bolt.support.json.dict.internal;

import com.bolt.support.json.dict.annotation.DictTranslate;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;

import java.util.List;

public class DictSerializerModifier extends BeanSerializerModifier {
    @Override
    public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
        for (BeanPropertyWriter beanProperty : beanProperties) {
            DictTranslate annotation = beanProperty.getAnnotation(DictTranslate.class);
            if (annotation != null) {
                beanProperty.assignNullSerializer(new DictDataSerializer(annotation));
            }
        }
        return beanProperties;
    }
}